<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of gridvecs</title>
  <meta name="keywords" content="gridvecs">
  <meta name="description" content="clear all; close all;">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">utilities</a> &gt; gridvecs.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for utilities&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>gridvecs
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>clear all; close all;</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function gridvecs(gridfile,x1,x2,y1,y2,ds,thresh,fname) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment">clear all; close all;
gridfile = '~gcowles/Data/NOAA_MITSG_TKE/mtm1b.nc';
x1 = 836100;
x2 = 935370;
y1 = -186230;
y2 = -125810;
ds = 2000;
fname = 'mtm1b_2km_nansound_vecs.dat';</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function gridvecs(gridfile,x1,x2,y1,y2,ds,thresh,fname)</a>
0002 
0003 <span class="comment">%clear all; close all;</span>
0004 <span class="comment">%gridfile = '~gcowles/Data/NOAA_MITSG_TKE/mtm1b.nc';</span>
0005 <span class="comment">%x1 = 836100;</span>
0006 <span class="comment">%x2 = 935370;</span>
0007 <span class="comment">%y1 = -186230;</span>
0008 <span class="comment">%y2 = -125810;</span>
0009 <span class="comment">%ds = 2000;</span>
0010 <span class="comment">%fname = 'mtm1b_2km_nansound_vecs.dat';</span>
0011 
0012 <span class="comment">% Find elements closest to a grid of points for cleaning up vector plots</span>
0013 <span class="comment">%</span>
0014 <span class="comment">% function [] = gridvecs(fname,x2,y1,y2,ds)</span>
0015 <span class="comment">%</span>
0016 <span class="comment">% DESCRIPTION:</span>
0017 <span class="comment">% Find elements closest to a grid of points for cleaning up vector plots</span>
0018 <span class="comment">%</span>
0019 <span class="comment">% INPUT:</span>
0020 <span class="comment">%    gridfile:  FVCOM netcdf output file containing x,y</span>
0021 <span class="comment">%    fname:  list of node numbers</span>
0022 <span class="comment">%    x1:  left side of bounding box</span>
0023 <span class="comment">%    x2:  right side of bounding box</span>
0024 <span class="comment">%    y1:  bottom of bounding box</span>
0025 <span class="comment">%    y2:  top of bounding box</span>
0026 <span class="comment">%    ds:  grid lengthscale</span>
0027 <span class="comment">%    thresh: threshold distance in units of x.  If nearest FVCOM point to the</span>
0028 <span class="comment">%            vector grid is greater than this distance, no point is assigned.</span>
0029 <span class="comment">%</span>
0030 <span class="comment">% OUTPUT:</span>
0031 <span class="comment">%    fname: file containing indices of node numbers where vectors should be plot</span>
0032 <span class="comment">%</span>
0033 <span class="comment">% Author(s):</span>
0034 <span class="comment">%    Geoff Cowles (University of Massachusetts Dartmouth)</span>
0035 <span class="comment">%</span>
0036 <span class="comment">% References</span>
0037 <span class="comment">%==============================================================================</span>
0038 
0039 
0040 <span class="comment">% open grid file and read data</span>
0041 <span class="keyword">if</span>(~exist(gridfile))
0042   error(<span class="string">'grid file does not exist'</span>)
0043 <span class="keyword">end</span>;
0044 
0045 nc = netcdf(gridfile);
0046 x  = nc{<span class="string">'x'</span>}(:);
0047 y  = nc{<span class="string">'y'</span>}(:);
0048 nVerts = numel(x);
0049 fprintf(<span class="string">'number of nodes in the mesh %d\n'</span>,nVerts);
0050 nc = close(nc);
0051 
0052 <span class="comment">% create the grid</span>
0053 [X,Y] = meshgrid(x1:ds:x2,y1:ds:y2);
0054 [il,jl] = size(X);
0055 node = zeros(il*jl,1);
0056 cnt   = 0;
0057 <span class="keyword">for</span> i=1:il
0058 <span class="keyword">for</span> j=1:jl
0059    xloc = X(i,j); 
0060    yloc = Y(i,j);
0061    dist = sqrt(   (x-xloc).^2 + (y-yloc).^2);  
0062    [mind,imin] = min(dist);
0063    <span class="keyword">if</span>(mind &lt; thresh);  
0064      cnt = cnt + 1;
0065      node(cnt) = imin;
0066    <span class="keyword">end</span>;
0067 <span class="keyword">end</span>;
0068 <span class="keyword">end</span>;
0069 node = node(1:cnt);  
0070 
0071 <span class="comment">% dump the list</span>
0072 fid = fopen(fname,<span class="string">'w'</span>);
0073 <span class="keyword">for</span> i=1:cnt
0074   fprintf(fid,<span class="string">'%d\n'</span>,node(i));
0075 <span class="keyword">end</span>;
0076 fclose(fid);</pre></div>
<hr><address>Generated on Wed 02-Nov-2011 21:58:00 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>